package com.deng.mina.common.protocol;

import org.apache.mina.core.buffer.IoBuffer;

import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

/**
 * @Project
 * @Module
 * @JDK_Vserion 1.8
 * @Author DengLibin
 * @Email dlb@smarthse.cn
 * @Desc 解码的上下文
 * @since 2019/9/18 0018 10:02
 */
public class DecoderContext {

    private CharsetDecoder charsetDecoder;
    private IoBuffer buffer; // 缓冲区 保存接收的的数据
    public DecoderContext(Charset charset){
        charsetDecoder = charset.newDecoder();
        buffer = IoBuffer.allocate(1 << 7).setAutoExpand(true);
    }

    /**
     * 追加数据包
     * @param in
     */
    public void appendToBuffer(IoBuffer in){
        this.buffer.put(in);
    }

    public CharsetDecoder getCharsetDecoder() {
        return charsetDecoder;
    }

    public void setCharsetDecoder(CharsetDecoder charsetDecoder) {
        this.charsetDecoder = charsetDecoder;
    }

    public IoBuffer getBuffer() {
        return buffer;
    }

    public void setBuffer(IoBuffer buffer) {
        this.buffer = buffer;
    }
}
